﻿@using Smartstore.Web.Models.Customers;

@model CustomerOrderListModel

<form asp-action="Orders">
    <div class="recurring-payments mb-4">
        <fieldset class="content-group mb-0">
            <legend class="mb-0">
                <span>@T("Account.CustomerOrders.RecurringOrders")</span>
            </legend>
            <div class="recurring-payments-box table-responsive">
                <table class="table table-striped table-hover">
                    <caption class="sr-only">@T("Account.CustomerOrders.RecurringOrders")</caption>
                    <thead>
                        <tr>
                            <th class="text-center border-0" scope="col">
                                @T("Order.Order#")
                            </th>
                            <th class="border-0" scope="col">
                                @T("Account.CustomerOrders.RecurringOrders.StartDate")
                            </th>
                            <th class="text-center border-0" scope="col">
                                @T("Account.CustomerOrders.RecurringOrders.CyclesRemaining")
                            </th>
                            <th class="border-0" scope="col">
                                @T("Account.CustomerOrders.RecurringOrders.NextPayment")
                            </th>
                            <th class="border-0" scope="col">
                                @T("Account.CustomerOrders.RecurringOrders.CycleInfo")
                            </th>
                            <th class="text-center border-0" scope="col">
                                @T("Account.CustomerOrders.RecurringOrders.TotalCycles")
                            </th>
                            <th class="border-0" scope="col">
                                &nbsp;
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.RecurringPayments)
                        {
                            var deleteTitle = T("Account.CustomerOrders.RecurringOrders.Cancel", item.InitialOrderNumber);
                            <tr>
                                <th scope="row" class="text-center">
                                    <a asp-action="Details" asp-controller="Order" asp-route-id="@item.InitialOrderId" rel="nofollow" title="@T("Order.OrderDetails")">
                                        @item.InitialOrderNumber
                                    </a>
                                </th>
                                <td title="@item.StartDate.ToString()">
                                    <time asp-for="@item.StartDate" sm-format="d"></time>
                                </td>
                                <td class="text-center">
                                    @item.CyclesRemaining
                                </td>
                                <td title="@item.NextPayment.ToString()">
                                    @(item.NextPayment != null ? item.NextPayment.Value.ToString("d") : string.Empty)
                                </td>
                                <td dir="auto">
                                    @item.CycleLength.ToString("N0") @item.CyclePeriodString
                                </td>
                                <td class="text-center">
                                    @item.TotalCycles.ToString("N0")
                                </td>
                                <td>
                                    <button sm-if="item.CanCancel" 
                                            type="submit"
                                            name="recurringPaymentId"
                                            value="@item.Id" 
                                            class="btn btn-icon btn-sm btn-to-danger confirm2"
                                            data-confirm-message="@T("Account.CustomerOrders.RecurringOrders.CancelDelivery")"
                                            title="@deleteTitle"
                                            aria-label="@deleteTitle">
                                        <i class="far fa-trash-can" aria-hidden="true"></i>
                                    </button>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div sm-if="Model.RecurringPayments.TotalPages > 1" class="mt-1">
                    <pagination sm-list-items="Model.RecurringPayments" sm-query-param="recurringPaymentsPage" id="rp-paginator" />
                </div>
            </div>
        </fieldset>
    </div>
</form>
